<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>修改密码</title>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">

		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="../js/ajax.js"></script>
		<script src="html5plus://ready"></script>
		<script type="text/javascript" src="../js/back.js"></script>
		<script type="text/javascript" src="../js/back1.js"></script>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	</head>
	<body>
		<div id="app">
			<van-row>
				<van-col span="24">
					<van-nav-bar id="spanber" fixed=true title="修改登录密码" right-text="确认修改" left-arrow @click-left="onClickLeft"
					 @click-right="onClickRight"></van-nav-bar>
					 <br/>
					 <br/>
				</van-col>
				<van-col span="24" class="xgyanzheng">
					<van-row>
						<van-col span="14" offset="1">
							<van-cell-group>
								<van-field v-model="phoneCode" placeholder="6位短信验证码" required></van-field>
							</van-cell-group>
						</van-col>
						<van-col span="7" offset="1">
							<van-button type="warning" @click="xgclick">发送验证码</van-button>
						</van-col>
					</van-row>
				</van-col>
				<van-col span="21" offset="1" class="xgyanzheng">
					<van-cell-group>
						<van-field type="password" v-model="pwd" placeholder="请输入登录密码" required></van-field>
					</van-cell-group>
				</van-col>
				<van-col span="21" offset="1" class="xgyanzheng">
					<van-cell-group>
						<van-field type="password" placeholder="再次输入新的登录密码" required></van-field>
					</van-cell-group>
				</van-col>

				<van-col span="22" offset="1">
					<h5>
						<van-icon name="info-o"></van-icon>
						系统将向你绑定的手机号码发送一条短信
					</h5>
				</van-col>

			</van-row>

		</div>
		<script>
			var vm = new Vue({
				el: "#app",
				data: {
					phoneCode: "",
					pwd: ""
				},
				methods: {
					onClickLeft: function() {					
						plus.webview.close(plus.webview.currentWebview().id);
					},
					onClickRight: function() {
						if (confirm('确定要更改吗') == true) {
							var _this = this
							ajax({
								url: "http://dsapi.ysd3g.com/API/ChangePassword",
								data: {
									key: localStorage.getItem('key'),
									password: _this.pwd,
									phoneCode: _this.phoneCode
								},
								dataType: "jsonp",
								success: function(res) {
									console.log(res)
									if (!res.Error) {
										alert("修改成功")
										plus.webview.create("Login.html", "login").show();
										plus.webview.close(plus.webview.currentWebview().id);
									} else {
										alert(res.Msg)
									}
								}
							})
						} else {
							alert("已取消更改")
						}

					},
					xgclick: function() {
						var _this = this
						ajax({
							url: "http://dsapi.ysd3g.com/API/SendChangePasswordCode",
							data: {
								key: localStorage.getItem('key')
							},
							dataType: "jsonp",
							success: function(res) {
								console.log(res)
								if (!res.Error) {
									alert(res.Code)
									_this.phoneCode = res.Code
								} else {
									alert(res.Msg)
								}
							}
						})
					},
					mounted() {
						if(localStorage.getItem('Key') == null){
							alert("登陆失效，请重新登陆")
							plus.webview.create("Login.html", "login").show();
						}
					}
				}
			})
		</script>
	</body>
</html>
